package org.oschina.api.favorite.type.controller;

import java.util.List;
import org.oschina.api.BaseController;
import org.oschina.api.favorite.type.model.FavoriteType;
import org.oschina.api.favorite.type.service.FavoriteTypeService;
import org.oschina.api.favorite.type.vo.FavoriteTypeVo;
import org.oschina.bean.Result;
import org.oschina.config.Config;
import org.oschina.handler.validator.annotation.Validate;
import org.oschina.handler.validator.annotation.ValidateField;
import org.oschina.handler.validator.filter.TextOnlyFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value=Config.API_PATH+"/favorite/type")
public class FavoriteTypeController extends BaseController {

	@Autowired
	private FavoriteTypeService favoriteTypeService;
	
	/**
	 * 返回
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public List<FavoriteTypeVo> findVo()
	{
		return favoriteTypeService.findVo();
	}
	
	/**
	 * 更新
	 * @param favoriteType
	 * @return
	 */
	@Validate
	@RequestMapping(value="/update/{id}",method=RequestMethod.POST)
	public Result update
	(
		@Validate(validateField=
		{
			@ValidateField(name="id",validateValue=true,min=1),
			@ValidateField(name="name",filter={TextOnlyFilter.class}),
			@ValidateField(name="url",filter={TextOnlyFilter.class})
		}) FavoriteType favoriteType
	)
	{
		return favoriteTypeService.update(favoriteType);
	}
}